import Mock from 'mockjs'



const userList = [{
  'username': 'admin',
  "password": 'admin'
}, {
  'username': '张三',
  "password": '123456'
}, {
  'username': '李四',
  "password": '66666'
}]

Mock.mock('/api/login', 'post', (req) => {
  const {
    username,
    password
  } = JSON.parse(req.body)

  const result = userList.find(item => item.username === username && item.password === password)

  if (result) {
    return {
      code: 200,
      token: username,
    }
  } else {
    return {
      code: 404
    }
  }
})


const data = Mock.mock({
  'list|100-200': [{
    key: "@id",
    name: "@cname",
    age: "@integer(18,30)",
    address: "@county(true)",
  }]
})

Mock.mock('/api/admin/list', 'post', () => {
  return {
    code: 200,
    data: data.list
  }
})